#ifndef PAGEMENUFILTER_H
#define PAGEMENUFILTER_H
#include <QObject>
#include <QEvent>
#include <QTableWidget>
#include <QMenu>
#include <QAction>
#include <QDebug>
#include <QContextMenuEvent>


class PageMenuFilter : public QObject {
    Q_OBJECT
public:
    explicit PageMenuFilter( QWidget * page ,QObject *parent = nullptr)
        : QObject(parent), page(page) {}

signals:
    void delete_trig();

protected:
    bool eventFilter(QObject *obj, QEvent *event) override {
        if (event->type() == QEvent::ContextMenu) {
            QContextMenuEvent *contextEvent = static_cast<QContextMenuEvent*>(event);

            // 创建右键菜单
            QMenu menu(page);
            QAction *actionDelete = menu.addAction("删除页面");


            // 显示菜单并处理选择
            QAction *selectedAction = menu.exec(contextEvent->globalPos());
            if(selectedAction == actionDelete){
                emit delete_trig();
            }
            return true; // 事件已处理
        }

        // 其他事件交给默认处理
        return QObject::eventFilter(obj, event);
    }
private:
    QWidget *page;
};


#endif // PAGEMENUFILTER_H
